#include <bits/stdc++.h>
using namespace std;
int main() {
  int T;
  cin >> T;
  while (T--) {
    int n;
    cin >> n;
    vector<int> pushed(n), poped(n);
    for (auto &x : pushed) cin >> x;
    for (auto &x : poped) cin >> x;
    stack<int> stk;
    int index = 0;
    for (auto &x : pushed) {
      stk.push(x);
      while (!stk.empty() && poped[index] == stk.top()) {
        stk.pop();
        index ++;
      }
    }
    cout << (stk.empty() ? "Yes" : "No") << endl;
  }
}